﻿using AutoMapper;
using MediatR;
using WarehouseManagement.Application.Command.WarehouseCommand;
using WarehouseManagement.Domain.Entity;
using WarehouseManagement.Infrstructre.Interface;

namespace WarehouseManagement.Application.CommandHandler.WarehouseCommandHandler
{
    /// <summary>
    /// 修改仓库信息
    /// </summary>
    public class WarehouseUpdCommandHandler:IRequestHandler<WarehouseUpdCommand,int>
    {
        private readonly IWarehouseRepository _warehouseRep;
        private readonly IMapper _mapper;
        public WarehouseUpdCommandHandler(IWarehouseRepository warehouseRep, IMapper mapper)
        {
            _warehouseRep = warehouseRep;
            _mapper = mapper;
        }

        public async Task<int> Handle(WarehouseUpdCommand request, CancellationToken cancellationToken)
        {
            return await _warehouseRep.UpdateAsync(_mapper.Map<Warehouse>(request.updDto));
        }
    }
}
